﻿Imports System
Imports System.Data.SqlClient
Imports System.Data

Public Class SeasonLocker
    Inherits System.Web.UI.Page

    'Open the connection to the database
    'Dim connectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=CIS441WinterParkWeb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
    Dim connectionString As String = "Data Source=SHANK-PC\SQLEXPRESS;Initial Catalog=WinterPark;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
    Dim connection As New SqlConnection(connectionString)
    Dim com As SqlCommand
    Dim str As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            loadCombos()
            LockerPriceTextBox.Text = ""
        End If

    End Sub
    Protected Sub loadCombos()
        'loading locker types
        connection.Open()
        str = "select '#Choose A Locker Type#' as LockerType union select LockerType from LockerTable order by LockerType "
        com = New SqlCommand(str, connection)
        Dim reader As SqlDataReader = com.ExecuteReader
        While reader.Read
            LockerTypeDropDownList.Items.Add(reader("LockerType"))
        End While
        reader.Close()

        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If

        'load customer data using SQL parameters
        str = " select '#Choose A Customer#' as CustomerName,-1 as CustomerID   union  select Surname + ', ' + Firstname as CustomerName,CustomerID  from CustomerTable order by CustomerName "
        com = New SqlCommand(str, connection)
        reader = com.ExecuteReader
        While reader.Read
            Dim lstItem As New ListItem(reader("CustomerName"), reader("CustomerID"))
            CustomerNameDropdownList.Items.Add(lstItem)
        End While
        reader.Close()

        connection.Close()

    End Sub

    Protected Sub MembershipTypeDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LockerTypeDropDownList.SelectedIndexChanged
        connection.Open()
        str = "select Lockerprice from LockerTable where LockerType=@par_LockerType"
        com = New SqlCommand(str, connection)
        com.Parameters.Add(New SqlParameter("@par_LockerType", LockerTypeDropDownList.SelectedValue))
        Dim reader As SqlDataReader = com.ExecuteReader
        If reader.Read Then
            LockerPriceTextBox.Text = reader("Lockerprice").ToString
        End If
        reader.Close()
        connection.Close()
    End Sub

    Private Sub btnGetCustomer_Click(sender As Object, e As EventArgs) Handles btnGetCustomer.Click
        connection.Open()
        'get the customer data from the 
        str = "select Street,City,State,ZipCode from CustomerTable where CustomerID=@par_CustomerID"
        com = New SqlCommand(str, connection)
        com.Parameters.Add(New SqlParameter("@par_CustomerID", CustomerNameDropdownList.SelectedValue))
        Dim reader As SqlDataReader = com.ExecuteReader
        If reader.Read Then
            AddressTextBox.Text = reader("Street").ToString
            CityZipTextBox.Text = reader("City").ToString + ", " + reader("State").ToString + "  " + reader("ZipCode").ToString
        End If
        reader.Close()
        connection.Close()

        'setting locker back to default
        LockerTypeDropDownList.SelectedIndex = -1
        LockerPriceTextBox.Text = ""
    End Sub

    Protected Sub LessonSignupButton_Click(sender As Object, e As EventArgs) Handles LessonSignupButton.Click
        Server.Transfer("Lesson.aspx")
    End Sub

    Protected Sub SeasonPassButton_Click(sender As Object, e As EventArgs) Handles SeasonPassButton.Click
        Server.Transfer("SeasonMembership.aspx")
    End Sub

    Protected Sub MainMenuButton_Click(sender As Object, e As EventArgs) Handles MainMenuButton.Click
        Server.Transfer("MainMenu.aspx")
    End Sub

    Protected Sub MaintenanceButton_Click(sender As Object, e As EventArgs) Handles MaintenanceButton.Click
        Server.Transfer("Maintenance.aspx")
    End Sub

    Protected Sub ReportsButton_Click(sender As Object, e As EventArgs) Handles ReportsButton.Click
        Server.Transfer("Reports.aspx")
    End Sub

    Protected Sub RegistrationButton_Click(sender As Object, e As EventArgs) Handles RegistrationButton.Click
        Server.Transfer("Registration.aspx")
    End Sub


End Class